﻿using Prism.Mvvm;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace AnChao.WPF.Controls.Prism.ViewModels
{
    public class DomainObject : BindableBase, INotifyDataErrorInfo
    {
        private  ErrorsContainer<string> _errorsContainer;

        public ErrorsContainer<string> ErrorsContainer
        {
            get 
            {
                if (_errorsContainer == null)
                {
                    _errorsContainer = new ErrorsContainer<string>(s=>OnErrorsChanged(s));
                }

                return _errorsContainer;
            }
        }


        public bool HasErrors => ErrorsContainer.HasErrors;

        public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

        public void OnErrorsChanged(string propertyName)
        {
            ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
        }

        public IEnumerable GetErrors(string propertyName)
        {
            return ErrorsContainer.GetErrors(propertyName);
        }
    }
}
